package edu.mit.media.fv.aqwidgets
{
	public class TimeUtil
	{
		public function TimeUtil()
		{
		}
		public static function toFullDateString(date:Date, gran:int):String{
			if(gran == 0){//year
				return date.fullYearUTC+" ";
			}else if(gran == 1){//month
				return toMonthString(date.monthUTC)+", "+date.fullYearUTC;
			}else if(gran == 2){//day
				return toDayString(date.dayUTC)+", "+toMonthString(date.monthUTC)
				+" "+date.dateUTC+", "+date.fullYearUTC;
			}else if(gran == 3){//hour
				return toDayString(date.dayUTC)+", "+toMonthString(date.monthUTC)
				+" "+date.dateUTC+", "+date.fullYearUTC+"    "
				+toMinuteString(date.hoursUTC, 0);
			}else if(gran == 4){//minute
				return toDayString(date.dayUTC)+", "+toMonthString(date.monthUTC)
				+" "+date.dateUTC+", "+date.fullYearUTC+"    "
				+toMinuteString(date.hoursUTC, date.minutesUTC);
			}else{
				return toDayString(date.dayUTC)+", "+toMonthString(date.monthUTC)
				+" "+date.dateUTC+", "+date.fullYearUTC+"    "
				+toMinuteString(date.hoursUTC, date.minutesUTC);
			}
			
		}
		public static function toMinuteString(h:Number, m:Number):String{
			if(h < 12){
				if(m<10){
					return h%12 + ":0"+m + "am";
				}else{
					return h%12 + ":"+m + "am";
				}
				
			}else{
				if(m<10){
					return h%12 + ":0"+m + " pm";
				}else{
					return h%12 + ":"+m + " pm";
				}
				
			}
			
		}
		public static function toHourString(n:Number):String{
			if(n < 12){
				return n%12 + " am";
			}else{
				return n%12 + " pm";
			}
			
		}
		public static function toYearString(n:Number):String{
			return n+"";
		}
		public static function toDayString(n:Number):String{
			if(n == 0){
				return "Sunday";
			}else if(n == 1){
				return "Monday";
			}else if(n == 2){
				return "Tuesday";
			}else if(n == 3){
				return "Wednesday";
			}else if(n == 4){
				return "Thursday";
			}else if(n == 5){
				return "Friday";
			}else if(n == 6){
				return "Saturday";
			}
			return "";
		}
		public static function toMonthString(n:Number):String{
			if(n == 0){
				return "January";
			}else if(n == 1){
				return "February";
			}else if(n == 2){
				return "March";
			}else if(n == 3){
				return "April";
			}else if(n == 4){
				return "May";
			}else if(n == 5){
				return "June";
			}else if(n == 6){
				return "July";
			}else if(n == 7){
				return "August";
			}else if(n == 8){
				return "September";
			}else if(n == 9){
				return "October";
			}else if(n == 10){
				return "November";
			}else if(n == 11){
				return "December";
			}
			return "";
		}

	}
}